import { getChannelList, updateSaasCompany } from '@/api/company'

import { Input, message } from 'ant-design-vue'
import { Component, Emit, Prop, Watch } from 'vue-facing-decorator'
import Render from '@/render/Render'
import renderModal, {
    getModelValue,
    initModelValue,
    type FormModalDto
} from '@/components/modal/Modal'
import toNative from '@/utils/toNative'
import { getReceiptData } from '@/utils/util'
import type { CompanyInfoDto } from '@/api/company/types'
import type { LongInsuranceCaseListDto,ReportCaseResultDto } from '@/api/insurance/period/types'
import { getKeyToEnum, InsuranceIndemnifyEnum } from '@/const/enum'
import { setPeriodInsurClaim,setDailyInsurClaimOne,setDailyInsurClaimTwo } from '@/api/insurance/period'
import type { VxeColumnSlotTypes } from 'vxe-table'
import type { TableRenderColumnTypes } from '@/render/TableRender'
@Component
export class AddRebatePop extends Render {
    insuranceGradeColor = { 
        '1-3类': 'text-green',
        '4类': 'text-blue-100',
        '5类': 'text-orange-100',
        '6类': 'text-red',
    } as Record<string, string>
    @Prop({ default: false }) show!: boolean
    @Prop() basicInfo!: LongInsuranceCaseListDto<ReportCaseResultDto>
    @Emit('update:show')
    showChange(val: boolean) {return val}

    @Emit('refresh')
    handleRefresh() {}

    @Watch('show', { immediate: true })
    async handleWatchShow() {
        this.formConfig.show = this.show
        if (this.show) {
            this.basicInfo.isVisible = 1
            initModelValue(this.formConfig, this.basicInfo)
        }
    }

    formConfig = this.initFormConfig() as FormModalDto

    initFormConfig() {
        return {
            title: '新增返利',
            theme: 'dark',
            width: '620px',
            show: false,
            items: {
                reportStatus: {
                    name: '',
                    element: 'customInsurancePriceTable',
                    params: {
                        tableColumnConfig: [
                            {
                                field: 'monthCost',
                                editRender: { name: 'VxeInput' },
                                slots: {
                                    header: ({ row, column }: VxeColumnSlotTypes.ContentSlotParams) => {
                                        return (
                                            <div class="text-center ">
                                                <span class="text-green ">1-3类</span>返利
                                            </div>
                                        )
                                    }
                                }
                            },
                            {
                                field: 'monthCost',
                                editRender: { name: 'VxeInput' },
                                slots: {
                                    header: ({ row, column }: VxeColumnSlotTypes.ContentSlotParams) => {
                                        return (
                                            <div class="text-center ">
                                                <span class="text-green ">4类</span>返利
                                            </div>
                                        )
                                    }
                                }
                                
                            },
                            {
                                field: 'monthCost',
                                editRender: {
                                    name: 'VxeInput',
                                    slots: {
                                        edit: ({ row, column }: VxeColumnSlotTypes.ContentSlotParams) => {
                                            return (
                                                <Input v-model:value={ row.monthCost } addon-after="%" placeholder="请输入返利额度" />
                                            )
                                        }
                                    }
                                },
                                slots: {
                                    header: ({ row, column }: VxeColumnSlotTypes.ContentSlotParams) => {
                                        return (
                                            <div class="text-center">
                                                <span class="text-green ">5类</span>返利
                                            </div>
                                        )
                                    }
                                }
                            },
                            {
                                field: 'monthCost',
                                editRender: { name: 'VxeInput' },
                                slots: {
                                    header: ({ row, column }: VxeColumnSlotTypes.ContentSlotParams) => {
                                        return (
                                            <div class="text-center ">
                                                <span class="text-green ">6类</span>返利
                                            </div>
                                        )
                                    }
                                }
                            }
                        ] ,
                        tableData: [{
                            grade: '1-3类',
                            monthCost: '10',
                            dayCost:'10'
                        },{
                            grade: '4类',
                            monthCost: '10',
                            dayCost:'10'
                        }]
                       
                    }
                },
                fileList: {
                    name: '上传文件',
                    element: 'upload',
                    required:true
                },
                effectiveDate: {
                    name: '生效日期',
                    element: 'datetime',
                    required:true
                },
                endDate: {
                    name: '结束日期',
                    element: 'datetime',
                    required:true
                }
				
            },
            complete: async () => {
                const data = getModelValue(this.formConfig)
                message.success('操作成功')
                this.handleRefresh()
                this.formConfig.show = false
                this.showChange(false)
            },
            cancel: () => {
                this.formConfig.show = false
                this.showChange(false)
            }
        } as FormModalDto
    }

    render() {
        return <div>{renderModal(this.formConfig)}</div>
    }
}

export default toNative<{  }, { refresh: () => void }>(AddRebatePop)
